/**
* Deposit Edit settings Page
*
* This page will render the GUI and the Deposit settings feilds. This page is
* commented extensively as the deposit code is used to base many payment modules
*
* @access 	public
* @author 	Rob, Valentin
* @copyright	ResMania 2009 all rights reserved.
* @version	1.0
* @link		http://developer.resmania.com/docs:creating_resmania_plugins
* @since  	05-2009
*/

RM.Pages.Plugin_Deposit_Config_Toolbar = {
    xtype : "panel",
    id : "rm_pages_plugins_deposit_toolbar",
    bodyBorder : false,
    html : RM.Common.getToolbar([{image: RM.BaseLargeImageURL+"save.gif", label: RM.Translate.Admin.Deposit.Main.Save, link: "RM.Pages.Functions.plugins_deposit_save()"}])
    // RM.Common.getToolbar usage: image, label, JS function to link to
}
RM.Toolbars.push(RM.Pages.Plugin_Deposit_Config_Toolbar);

RM.Pages.Functions.plugins_deposit_save = function(){
    RM.Pages.Plugin_Deposit_Panel.getForm().submit({        
        success: function(form, action) {
            RM.Pages.Units_StatusBar = Ext.getCmp('rm_pages_plugins_deposit_statusbar');
            RM.Pages.Units_StatusBar.setStatus({
                text: RM.Translate.Admin.Deposit.Main.SaveOK,
                iconCls: 'ok-icon'
            });
        },
        failure: function() {
            RM.Pages.Units_StatusBar = Ext.getCmp('rm_pages_plugins_deposit_statusbar');
            RM.Pages.Units_StatusBar.setStatus({
                text: RM.Translate.Admin.Deposit.Main.SaveFailed,
                iconCls: 'failed-icon'
            });
        },
        waitMsg: RM.Translate.Common.Saving,
        waitTitle: RM.Translate.Common.PleaseWait
    });
}

// the hidden ID feild use to connect this to the DB record.
RM.Pages.Plugin_Deposit_ID_Field = new Ext.form.Hidden({
    id : "rm_pages_plugins_deposit[id]",
    name : "rm_pages_plugins_deposit[id]"
});

// enabled checkbox
RM.Pages.Plugin_Deposit_Enabled_Field = new Ext.ux.form.XCheckbox({
    id: "rm_pages_plugins_deposit[enabled]",
    name: "rm_pages_plugins_deposit[enabled]",
    inputValue: "1",
    boxLabel: RM.Translate.Admin.Deposit.Main.Enabled
});

// type selection
RM.Pages.Plugin_Deposit_Type_Field = new Ext.form.ComboBox({
    id: 'rm_pages_plugins_deposit[type]',
    name: 'rm_pages_plugins_deposit[type]',
    fieldLabel: RM.Translate.Admin.Deposit.Main.Type,
    mode: 'local',
    displayField: "type",
    triggerAction: 'all',
    typeAhead: true,
    resizable: true,
    width: 140,
    minListWidth: 140,
    store: [
        ['percentage', RM.Translate.Admin.Deposit.Type.Percentage],
        ['amount', RM.Translate.Admin.Deposit.Type.Amount]
    ]
});

RM.Pages.Plugin_Deposit_Value_Field = new Ext.form.TextField({
    fieldLabel: RM.Translate.Admin.Deposit.Main.Value,
    id : "rm_pages_plugins_deposit[value]",
    name : "rm_pages_plugins_deposit[value]",
    width : 50
});

// enabled checkbox
RM.Pages.Plugin_Deposit_Force_Field = new Ext.ux.form.XCheckbox({
    id: "rm_pages_plugins_deposit[force]",
    name: "rm_pages_plugins_deposit[force]",
    inputValue: "1",
    boxLabel: RM.Translate.Admin.Deposit.Main.Force
});

// the feildset to make it look pretty
// notice 'items' contains all the above form items
RM.Pages.Plugin_Deposit_Fieldset = new Ext.form.FieldSet({
    title: RM.Translate.Admin.Deposit.Main.Settings,
    autoHeight: true,
    layout: 'form',
    bodyBorder : false,
    items: [
        RM.Pages.Plugin_Deposit_ID_Field,
        RM.Pages.Plugin_Deposit_Type_Field,
        RM.Pages.Plugin_Deposit_Value_Field,
        RM.Pages.Plugin_Deposit_Force_Field,
        RM.Pages.Plugin_Deposit_Enabled_Field
    ]
});

RM.Pages.Functions.Deposit_ConfigJson = function (responseObject) {
    var settings = responseObject.settings;

    for (var key in settings) {
        Ext.getCmp("rm_pages_plugins_deposit["+key+"]").setValue(settings[key]);
    }

    // just do so ExtJS stuff to ensure the GUI is rendered and visible
    Ext.getCmp('rm_pages_plugins_deposit_main_form').render();
    Ext.getCmp('rm_pages_plugins_deposit_main_form').doLayout();

    Ext.getCmp('toolbar_panel').layout.setActiveItem('rm_pages_plugins_deposit_toolbar');
    Ext.getCmp('content-panel').layout.setActiveItem('rm_pages_plugins_deposit_main_form');

    //RM.Help.Load('Admin.Deposit.Edit.Main');
}

RM.Pages.Plugin_Deposit_Panel = new Ext.FormPanel({
    id : 'rm_pages_plugins_deposit_main_form',
    title: RM.Translate.Admin.Deposit.Main.Title,
    bodyStyle : "padding:10px;",
    items : [
        RM.Pages.Plugin_Deposit_Fieldset
    ],
    url : RM.Common.AssembleURL({
        controller: 'Deposit',
        action: 'updateJson'
    }),
    bbar: new Ext.ux.StatusBar({
        id: 'rm_pages_plugins_deposit_statusbar',
        items: []
    })
});

RM.Main.Pages.push(RM.Pages.Plugin_Deposit_Panel);